<html>

<body>
用户名<input type="text" id="username"><br />
密码<input type="password" id="password"><br />
<input type="checkbox" id="remember">记住我<br />
<input type="button" value="登录" />

<script>
    var g = function(v){
        return document.getElementById(v)
    }
    g('remember').onclick = function(){
        if(this.checked==true){
            //记住用户名和密码
            localStorage.setItem(
                "username",
                g("username").value
            );
            localStorage.setItem(
                "password",
                g("password").value
            );
        }else{
            //删除用户名和密码
            localStorage.removeItem(
                "username"
            );
            localStorage.removeItem(
                "password"
            );
            
        }
    }
    
    
    g("username").value = localStorage.getItem("username");
    g("password").value = localStorage.getItem("password");
    
    
    

</script>
</body>
</html>